# Figure 4

#####
rm(list=ls(all=TRUE))

library(MASS)
library(stargazer)
library(sjPlot)
library(tidyverse)
library(ggpubr)

#### Dataset Original ####
setwd("/Users/sebastian/Dropbox/The politics of interruptions - JOP RR/Replication Files/Data Rep")
load("data_empirics_count_rep.Rdata")
load("data_empirics_length_rep.Rdata")
load("data_empirics_rep.Rdata")

data_empirics_interruptions <- data_empirics[data_empirics$interruption_final_dummy==1,]  
data_empirics_count$female_dum <- factor(data_empirics_count$female_dum, labels = c("Men", "Women"))
data_empirics_interruptions$female_dum <- factor(data_empirics_interruptions$female_dum, labels = c("Men", "Women"))

data_empirics_length$tot_num_speeches_session_10 <- (data_empirics_length$tot_num_speeches_session)/10

data_empirics_count$committee_chair <-as.factor(data_empirics_count$committee_chair)
data_empirics_interruptions$committee_chair <-as.factor(data_empirics_interruptions$committee_chair)
data_empirics_length$committee_chair <-as.factor(data_empirics_length$committee_chair)

## Access ##
model_access_1 <- glm.nb(tot_speeches_leg_cohort ~ female_dum + ideology_ext + 
                           committee_chair + seniority + type_member +
                           party_match_pres + 
                           negative_lang_mean + mujeres_mean +
                           factor(cohort) + committee_chair*female_dum , 
                         data = data_empirics_count)

model_access_2 <- glm.nb(tot_speeches_leg_cohort ~ female_dum + ideology_ext + 
                           committee_chair + seniority + type_member +
                           party_match_pres + 
                           negative_lang_mean + mujeres_mean +
                           factor(cohort) + seniority*female_dum , 
                         data = data_empirics_count)

## Floor time ##

model_length_1 <- glm.nb(length_speech_combined_session ~ female_dum + ideology_ext + 
                           committee_chair + seniority + type_member +
                           party_match_pres + 
                           election_year  +
                           negative_lang_w + mujeres_dummy +
                           tot_num_speeches_session_10 + mean_length_leg +
                           factor(cohort) + committee_chair*female_dum 
                         , 
                         data = data_empirics_length)

model_length_2 <- glm.nb(length_speech_combined_session ~ female_dum + ideology_ext + 
                           committee_chair + seniority +type_member +
                           party_match_pres + 
                           election_year  +
                           negative_lang_w + mujeres_dummy +
                           tot_num_speeches_session_10 + mean_length_leg +
                           factor(cohort) +seniority*female_dum
                         , 
                         data = data_empirics_length)

### Floor Time Before Interruption 

model_before_int <- glm.nb(length_speech_nocont ~ female_dum + ideology_ext + 
                             committee_chair + seniority + type_member +
                             party_match_pres + 
                             election_year +
                             tot_num_speeches_session_10 + mean_length_leg +
                             negative_lang_w + mujeres_dummy +
                             factor(cohort) + committee_chair*female_dum 
                           , 
                           data = data_empirics_interruptions)

model_before_int_2 <- glm.nb(length_speech_nocont ~ female_dum + ideology_ext + 
                               committee_chair + seniority + type_member +
                               party_match_pres + 
                               election_year +
                               tot_num_speeches_session_10 + mean_length_leg +
                               negative_lang_w + mujeres_dummy +
                               factor(cohort) + seniority*female_dum
                             , 
                             data = data_empirics_interruptions)

#### FIGURE 4: Interactions High Reputation ####
setwd("/Users/sebastian/Dropbox/The politics of interruptions - JOP RR/Replication Files/Figures")

access_1 <- plot_model(model_access_1, type = "pred", terms = c("committee_chair","female_dum")) +
  labs(y = "Predicted Number of Speeches",
       title = "Predicted number of speeches") +
  theme(legend.position="bottom")

access_2 <- plot_model(model_access_2, type = "pred", terms = c("seniority","female_dum")) +
  labs(y = "Prediced Number of Speeches", x = "Seniority",
       title = "Predicted number of speeches") +
  theme(legend.position="bottom")

length_1 <- plot_model(model_length_1, type = "pred", terms = c("committee_chair","female_dum")) +
  labs(y = "Predicted Length of Speech",
       title = "Predicted Length of Speech") +
  theme(legend.position="bottom")

length_2 <- plot_model(model_length_2, type = "pred", terms = c("seniority","female_dum")) +
  labs(y = "Prediced Length of Speeches", x = "Seniority",
       title = "Predicted Length of Speech") +
  theme(legend.position="bottom")

length_before_1 <- plot_model(model_before_int, type = "pred", terms = c("committee_chair","female_dum")) +
  labs( y = "Predicted Length of Speech",
        title = "Predicted Length of Speech",
        subtitle = "Note: Before an interruptions") +
  theme(legend.position="bottom")

length_before_2 <- plot_model(model_before_int_2, type = "pred", terms = c("seniority","female_dum")) +
  labs( y = "Predicted Length of Speech",
        title = "Predicted Length of Speech",x = "Seniority",
        subtitle = "Note: Before an interruptions") +
  theme(legend.position="bottom")

### All together now:

combined_high <- ggarrange(access_1,access_2, length_1,length_2, length_before_1,
                           length_before_2,
                           # labels = c("Chile","Ecuador"),
                           ncol = 2, nrow = 3,common.legend = T,
                           legend = "bottom")

combined_high
ggsave("figure4.pdf", width = 14, height = 12)



